//
//  MainTabControl.m
//  KaiYan
//
//  Created by tqh on 16/5/17.
//  Copyright © 2016年 tqh. All rights reserved.
//

#import "MainTabControl.h"
#import "KaiYanTabBar.h"
@interface MainTabControl ()

@property (nonatomic,strong)KaiYanTabBar *kaiyanTabBar;

@end

@implementation MainTabControl

#pragma mark - 懒加载

- (KaiYanTabBar *)kaiyanTabBar {
    if (!_kaiyanTabBar) {
        _kaiyanTabBar = [KaiYanTabBar new];
        _kaiyanTabBar.frame = CGRectMake(0, CGRectGetHeight(self.view.bounds)-44, CGRectGetWidth(self.view.bounds), 44);
    }
    return _kaiyanTabBar;
}

- (NSArray *)itemArray {
    NSArray *array = @[@"每日精选",@"发现更多",@"热门排行"];
    NSMutableArray *mutable = [NSMutableArray array];
    [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        KaiYanTabItem *item = [[KaiYanTabItem alloc]init];
        item.label.text = array[idx];
        [mutable addObject:item];
    }];
    return mutable;
}

#pragma mark - 生命周期

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tabBar.hidden = YES;
    [self.view addSubview:self.kaiyanTabBar];
    self.kaiyanTabBar.items = [self itemArray];
    [self addEvent];
}

#pragma mark - 添加事件

- (void)addEvent {
    [self tabBarSelectItemEvent];
}

#pragma mark - 事件监听

- (void)tabBarSelectItemEvent {
    __block MainTabControl *myself = self;
    [self.kaiyanTabBar setButtonIndexBlock:^(NSInteger index) {
        myself.selectedIndex = index;
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
